package com.test;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import java.io.File;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ColorDialog extends JFrame implements ActionListener {
JButton b1;
JButton b2;
JButton b3;
public static void main(String arg[]) {
new ColorDialog();
}
public ColorDialog() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
} );
setLocation(250,150);
Container pane = getContentPane();
pane.setLayout(new FlowLayout());
b1 = new JButton("Buttons");
b1.addActionListener(this);
pane.add(b1);
b2 = new JButton("Letters");
b2.addActionListener(this);
pane.add(b2);
pack();

setVisible(true);
}
public void actionPerformed(ActionEvent e) {
int retval;
String selection = e.getActionCommand();
if(selection.equals("Buttons")) {
Color color = JColorChooser.showDialog(this,
"Select background color of buttons",
b1.getBackground());
b1.setBackground(color);
b2.setBackground(color);
} else if(selection.equals("Letters")) {
Color color = JColorChooser.showDialog(this,
"Select color of button text",
b1.getForeground());
b1.setForeground(color);
b2.setForeground(color);
repaint();
}
}
}